//
//  VRLiveToolView.swift
//  VoiceRoom
//
//  Created by Rae on 2024/4/10.
//

import UIKit


class VRLiveToolView: UIView, SAAnimationDelegate, SAAnimationProtocol {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 170.0)
    }
    
    func animationContainerViewStyle() -> SAAnimationViewStyle {
        .bottom
    }
    
//    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
//        .dismiss
//    }
    private lazy var titleLabel = c_make_ex(UILabel.self)
        .color(.white).font(18.font_bold)
        .text("Room Tools").end()
    private let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = "#1F1E18".toColor
        self.fj.corner(20, corners: [.layerMinXMinYCorner,.layerMaxXMinYCorner])
        
        subviews{
            titleLabel
            collectionView
        }
        
        titleLabel.leading(15).top(20)
        collectionView.leading(0).trailing(0).top(57).bottom(0)
        
        let layout = UICollectionViewFlowLayout()
        layout.minimumLineSpacing = 30
        layout.minimumInteritemSpacing = 30
        layout.itemSize = CGSize(width: 55, height: 80)
        layout.sectionInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
        layout.scrollDirection = .horizontal
        collectionView.style { v in
            v.collectionViewLayout = layout
            v.backgroundColor = .clear
            v.register(VRLiveToolCell.self, forCellWithReuseIdentifier: VRLiveToolCell.description())
            v.showsHorizontalScrollIndicator = false
            v.delegate = self
            v.dataSource = self
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension VRLiveToolView: UICollectionViewDelegate,UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let item = collectionView.dequeueReusableCell(withReuseIdentifier: VRLiveToolCell.description(), for: indexPath) as? VRLiveToolCell else { return UICollectionViewCell() }
//        item.model = dataSource[indexPath.row]
        return item
    }
}


class VRLiveToolCell: UICollectionViewCell {
    
    private let iconView            = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).end()
    private lazy var titleLabel = c_make_ex(UILabel.self)
        .color(.white.alpha(0.8)).font(14.font_medium)
        .alignment(.center).end()

    var model:VRToolItemModel? {
        didSet{
            guard let md = model else { return }
            iconView.image = md.icon.toImage
            titleLabel.text = md.title
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)

        backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        subviews {
            iconView
            titleLabel
        }
        iconView.size(55).top(0).leading(0).trailing(0)
        titleLabel.leading(0).trailing(0)
        titleLabel.Top == iconView.Bottom + 7
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

}
